package com.nclg.exam.service.impl;

import com.nclg.exam.dto.UpdateUserDto;
import com.nclg.exam.entity.TUser;
import com.nclg.exam.mapper.UserMapper;
import com.nclg.exam.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 查询用户是否存在
     * @param uAccount
     * @return
     */
    @Override
    public TUser selectByAccount(String uAccount) {
        return userMapper.selectByAccount(uAccount);
    }

    /**
     * 注册用户
     * @param tUser
     * @return
     */
    @Override
    public boolean insertSelective(TUser tUser) {
        return userMapper.insertSelective(tUser) > 0 ? true : false;
    }

    /**
     * 通过uid查询用户
     * @param uId
     * @return
     */
    @Override
    public TUser selectByPrimaryKey(Long uId){
        return userMapper.selectByPrimaryKey(uId);
    }

    /**
     * 修改密码
     * @param uId
     * @param newPwd
     * @return
     */
    @Override
    public boolean updatePwd(Long uId, String newPwd) {
        return userMapper.updatePwd(uId, newPwd) > 0 ? true : false;
    }

    /**
     * 修改个人信息
     * @param dto
     * @return
     */
    @Override
    public boolean updateByPrimaryKeySelective(UpdateUserDto dto) {
        return userMapper.updateByPrimaryKeySelective(dto) > 0 ? true : false;
    }


}
